<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :md="6" :sm="24">
            <a-form-item label="表名称">
              <a-input placeholder="请输入表名称" v-model="queryParam.fdTabname"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="运行状态">
              <j-dict-select-tag placeholder="请选择运行状态" v-model="queryParam.fdStatus"  dictCode="run_status"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons" >
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px" >重置</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 操作按钮区域 -->
   <!-- <div class="table-operator" :md="24" :sm="24" style="margin: 0px 0px 20px 0px">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>

      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>-->

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange"
        :rowClassName="tableRowClassName">
        <!-- 字符串超长截取省略号显示-->
        <span slot="fdBatchId" slot-scope="text">
          <j-ellipsis :value="text" :length="9" />
        </span>

        <span slot="action" slot-scope="text, record">
        <!--  <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>-->
                <a href="javascript:;" @click="handleDetail(record)">详情</a>
              <!--</a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>-->
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <RunDetail-modal ref="modalForm" @ok="modalFormOk"/>
  </a-card>
</template>

<script>
  import RunDetailModal from './modules/RunDetailModal'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import {getAction} from '@/api/manage'
  import JEllipsis from "@/components/jeecg/JEllipsis";

  export default {
    name: "RunDetailList",
    mixins: [JeecgListMixin],
    components: {
      RunDetailModal,
      JEllipsis,
    },
    data() {
      return {
        description: '信息',
        // 表头
        columns: [
          {
            title: '批次',
            align:"center",
            dataIndex: 'fdBatchId',
            scopedSlots: {customRender: 'fdBatchId'},
          },
          {
            title: '表名称',
            align:"center",
            dataIndex: 'fdTabname'
          },
          {
            title: '运行状态',
            align:"center",
            dataIndex: 'fdStatus_dictText'
          },
         /* {
            title: '表id',
            align:"center",
            dataIndex: 'fdTabid'
          },*/
          {
            title: '运行开始时间',
            align:"center",
            dataIndex: 'fdStartTime'
          },
          {
            title: '运行结束时间',
            align:"center",
            dataIndex: 'fdEndTime'
          },
          {
            title: '运行时长',
            align:"center",
            dataIndex: 'fdTime'
          },
          {
            title: '运行参数',
            align:"center",
            dataIndex: 'fdParam'
          },
         /* {
            title: '创建人',
            align:"center",
            dataIndex: 'createUser'
          },
          {
            title: '修改人',
            align:"center",
            dataIndex: 'updateUser'
          },
          {
            title: '是否删除',
            align:"center",
            dataIndex: 'isDelete'
          },*/
         {
          title: '操作',
          key: 'operation',
          align: "center",
          width: 130,
          scopedSlots: {customRender: 'action'},
        }],
        url: {
          list: "/run/run/listRunDetailByMainId",
          delete: "/run/run/deleteRunDetail",
          deleteBatch: "/run/run/deleteBatchRunDetail",
        }
      }
    },
    methods: {
      loadData(arg) {
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        var params = this.getQueryParams();//{mainId: params.mainId,fdTabname: params.fdTabname,fdBatchId: params.fdBatchId}
        params.fdTabname = params.fdTabname != undefined ? "*" + params.fdTabname+ "*" : params.fdTabname;
        this.loading = true;

        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
          } else {
            this.dataSource = null;
          }
          this.loading = false;

        })
      },
      getFdBatchId(fdBatchId) {
        this.queryParam.fdBatchId = fdBatchId;
        this.loadData(1);
      },
      tableRowClassName(record) {
        return record.fdStatus_dictText === '错误' ? 'class-a' : '';
      },
      handleAdd: function () {
        this.$refs.modalForm.add(this.queryParam.fdBatchId);
        this.$refs.modalForm.title = "添加运行监控详情表";
      }, searchQuery:function(){
      this.selectedRowKeys = [];
      this.selectionRows = [];
      this.loadData();
    },searchReset:function() {
        this.queryParam = {fdBatchId : this.queryParam.fdBatchId};
        this.loadData(1);
      }

    }
  }
</script>
<style scoped>
  .ant-card {
    margin-left: -30px;
    margin-right: -30px;
  }
</style>
